package com.ruoyi.web.controller.agoniapp;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.UserIdByRequest;
import com.ruoyi.system.pojo.dto.MessageUserDTO;
import com.ruoyi.system.pojo.dto.SendMessageDataDTO;
import com.ruoyi.system.pojo.vo.MessageUserVO;
import com.ruoyi.system.pojo.vo.UserChatVO;
import com.ruoyi.system.service.IAgoniMessageService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/agoniapp/message")
public class MessageController {


    @Autowired
    private IAgoniMessageService agoniMessageService;


    @GetMapping("getMessageUserListBytoken")
    public AjaxResult getMessageUserListBytoken(HttpServletRequest request){

        //获取userId
        Long userId= UserIdByRequest.getUserId(request);

        //根据userId查询用户列表
       List<MessageUserVO> messageUserList= agoniMessageService.getMessageUserListBytoken(userId);

        System.out.println("messageUserlist"+messageUserList);
        return AjaxResult.success("查询成功",messageUserList);
    }


    @PostMapping("getMessageList")
    public AjaxResult getMessageList(@RequestBody MessageUserDTO messageUserDTO){

        List<UserChatVO> chatList=agoniMessageService.getChatList(messageUserDTO);

        return AjaxResult.success("查询成功",chatList);
    }


    @PostMapping("sendMessage")
    public AjaxResult sendMessage(@RequestBody SendMessageDataDTO sendMessageDataDTO) {


        Boolean result=agoniMessageService.sendMessage(sendMessageDataDTO);

if (result){
        return AjaxResult.success("发送成功");
}

        return AjaxResult.error("api接口调用失败");
    }


}
